package com.zack.gank.gankandroid.main.main.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gank.zack.ganklibrary.view.staggeredgrid.util.DynamicHeightImageView;
import com.zack.gank.gankandroid.gankandroid.R;
import com.zack.gank.gankandroid.main.find.bean.Gank;

import java.util.List;

/**
 * Created by Android on 2017/7/18.
 */
public class SeaxyGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<Gank> ganks;
    private List<Integer> listHeight;
    public SeaxyGridAdapter(Context context,List<Gank> list) {
        this.mContext=context;
        this.ganks=list;

    }

    @Override
    public int getCount() {
        return ganks.size();
    }

    @Override
    public Object getItem(int position) {
        return ganks.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SeaxyViewHolder viewHolder;
        if(convertView==null){
            convertView=LayoutInflater.from(mContext).inflate(R.layout.seaxy_layout_adapter,parent,false);
            viewHolder=new SeaxyViewHolder();
            viewHolder.ivGank= (ImageView) convertView.findViewById(R.id.iv_seaxy);
            viewHolder.tvAuthor= (TextView) convertView.findViewById(R.id.tv_author);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (SeaxyViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(ganks.get(position).url).into(viewHolder.ivGank);
        viewHolder.tvAuthor.setText(ganks.get(position).who);
        return convertView;
    }
    static  class SeaxyViewHolder{
        ImageView ivGank;
        TextView tvAuthor;
    }
}
